<template>
  <div class="mod-user">
    <el-form :inline="true" :model="formData">
      <el-form-item label="用户姓名/手机号">
        <el-input @blur="searchChange" placeholder="姓名/手机号" v-model="formData.code" size="small"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click.stop="searchChange">搜索</el-button>
      </el-form-item>
    </el-form>
    <div style="margin-bottom: 12px;padding-left: 6px">
      <el-button icon="el-icon-refresh" type="primary" @click.stop="refresh">更新数据</el-button>
    </div>
    <avue-crud ref="crud"
               :page="page"
               :data="dataList"
               :option="tableOption"
               @on-load="getDataList">
      <template slot-scope="scope" slot="isContact">
        <el-tag v-if="scope.row.isContact === 0"
                size="small"
                type="danger">未绑定</el-tag>
        <el-tag v-else
                size="small">已绑定</el-tag>
      </template>
      <template slot-scope="scope"
                slot="menu">
        <el-button type="primary" size="small" @click.stop="thirdPay(scope.row)">支付配置</el-button>
        <el-button v-if="scope.row.isContact === 0" type="success" size="small" @click.stop="bindPay(scope.row.id)">绑定支付</el-button>
        <el-button v-if="scope.row.isContact === 1" type="danger" size="small" @click.stop="unBindPay(scope.row.id)">解除绑定</el-button>
      </template>
    </avue-crud>
    <third-pay-config ref="thirdPayConfig" @refreshDataList="getDataList"></third-pay-config>
  </div>
</template>

<script>
  import { tableOption } from '@/crud/thirdpay/partnerList'
  import thirdPayConfig from './partner-thirdpay-config'
  export default {
    components: {
      thirdPayConfig
    },
    data () {
      return {
        dataList: [],
        dataListLoading: false,
        tableOption: tableOption,
        formData: {
          code: ''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        }
      }
    },

    methods: {
      // 获取数据列表
      getDataList (page, params) {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/v1/partner/third/pay/list'),
          method: 'get',
          params: this.$http.adornParams(
            Object.assign(
              {
                current: page == null ? this.page.currentPage : page.currentPage,
                size: page == null ? this.page.pageSize : page.pageSize
              },
              params
            )
          )
        }).then(({ data }) => {
          this.dataList = data.data.records
          this.page.total = data.data.total
          this.dataListLoading = false
        })
      },
      searchChange () {
        console.log(this.formData)
        this.page.currentPage=1
        this.getDataList(this.page, this.formData)
      },
      // 刷新
      refresh () {
        this.$confirm(`确定进行更新数据操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/v1/partner/third/pay/refresh'),
            method: 'POST',
            data: this.$http.adornData({})
          }).then(({ data }) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList(this.page)
              }
            })
          })
        })
          .catch(() => { })
      },

      thirdPay (row) {
        this.$refs.thirdPayConfig.init(row)
      },

      bindPay (id) {
        this.$confirm(`确定进行绑定支付操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/v1/partner/third/pay/contact/mer'),
            method: 'POST',
            data: this.$http.adornData(
              Object.assign(
                {
                  id: id
                }
              )
            )
          }).then(({ data }) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList(this.page)
              }
            })
          })
        })
          .catch(() => { })
      },

      unBindPay (id) {
        this.$confirm(`确定进行解除绑定支付操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/v1/partner/third/pay/uncontact/mer'),
            method: 'POST',
            data: this.$http.adornData(
              Object.assign(
                {
                  id: id
                }
              )
            )
          }).then(({ data }) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList(this.page)
              }
            })
          })
        })
          .catch(() => { })
      },

      // 运营商账户列表
      merchant_User (merchantId) {
        this.$router.push({
          path: '/merchantUser',
          query: {
            id: merchantId
          }
        })
      }
    }
  }
</script>

<style lang="scss">
  .remain{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    input{
      width: 100px;
    }
  }
  .sumary-list{
    display: flex;
    justify-content: flex-start;
    margin-bottom: 15px;
    div{
      height: 30px;
      padding: 0px 12px;
      line-height: 30px;
      border:solid 1px #009FF1;
      border-radius: 15px;
      margin-right: 10px;
    }
    div:hover{
      color: white;
      background-color: #009FF1;
    }
  }
</style>

